package com.fan.shop.mock;

import java.math.BigDecimal;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.fan.shop.dao.ItemDaoImpl;
import com.fan.shop.dao.StockDaoImpl;
import com.fan.shop.dao.StoreDaoImpl;
import com.fan.shop.domain.Item;
import com.fan.shop.domain.Stock;
import com.fan.shop.domain.StockId;
import com.fan.shop.hibernate.utils.HibernateUtil;

public class StockMock {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		StockMock test = new StockMock();
		test.insertStocks();

	}
	
	
	public void insertStocks()
	{
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.getCurrentSession();
		Transaction transaction = session.beginTransaction();
		
		ItemDaoImpl itemDaoImpl = new ItemDaoImpl();
		itemDaoImpl.setSessionFactory(sessionFactory);
		
		StoreDaoImpl storeDaoImpl = new StoreDaoImpl();
		storeDaoImpl.setSessionFactory(sessionFactory);
		
		StockDaoImpl stockDaoImpl = new StockDaoImpl();
		stockDaoImpl.setSessionFactory(sessionFactory);
		
		for(Item item : itemDaoImpl.getAllItems())
		{
			Stock stock = new Stock();
			
			StockId stockId = new StockId();
			stockId.setItemCode(item.getItemCode());
			stockId.setStoreCode("lg");
			stock.setId(stockId);
			stock.setQuantity(100);
			stock.setCost(new BigDecimal(20.0));
			stock.setNetPrice(new BigDecimal(50.00));
			
			stockDaoImpl.addStock(stock);
		}
		transaction.commit();
	}

}
